import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import List from '../views/List.vue'
import My from '../views/My.vue'

import Detail from '../views/Detail.vue'
import Searchlist from '../views/Searchlist.vue'
import Ress from '../views/Ress.vue'
import Order from '../views/Order.vue'
import AddRess from '../views/AddRess.vue'
import Video from '../views/Video.vue'
import Search from '../views/Search.vue'
import Searchgoods from '../views/Searchgoods.vue'
import Login from '../views/Login/Login.vue'
import Reg1 from '../views/Login/Reg1.vue'
import Reg2 from '../views/Login/Reg2.vue'
import Yzm from '../views/Login/Yzm.vue'
import Sett from '../views/Login/Set.vue'
import Password from '../views/Login/Password.vue'
import ShopingCart from '../views/ShopCart/ShopingCart.vue'

Vue.use(VueRouter)

const routes = [{
        path: '/',
        name: 'Home',
        component: Home
            // component: () =>
            //     import ( /* webpackChunkName: "about" */ '../views/AboutView.vue')
    },
    {
        path: '/Detail/:proid',
        name: 'Detail',
        component: Detail
    },
    {
        path: '/Video',
        name: 'Video',
        component: Video
    },
    {
        path: '/Searchlist/:keyword',
        name: 'Searchlist',
        component: Searchlist
    },
    {
        path: '/Ress',
        name: 'Ress',
        component: Ress
    },
    {
        path: '/Order',
        name: 'Order',
        component: Order
    },
    {
        path: '/AddRess',
        name: 'AddRess',
        component: AddRess
    },
    {
        path: '/My',
        name: 'My',
        component: My
    },
    {
        path: '/Search',
        name: 'Search',
        component: Search
    },
    {
        path: '/List',
        name: 'List',
        component: List
    },
    {
        path: '/Login',
        name: 'Login',
        component: Login
    },
    {
        path: '/Reg1',
        name: 'Reg1',
        component: Reg1
    },
    {
        path: '/Searchgoods/:name',
        name: 'Searchgoods',
        component: Searchgoods
    },
    {
        path: '/Reg2',
        name: 'Reg2',
        component: Reg2
    },
    {
        path: '/Yzm',
        name: 'Yzm',
        component: Yzm
    },
    {
        path: '/Sett',
        name: 'Sett',
        component: Sett
    },
    {
        path: '/ShopingCart',
        name: 'ShopingCart',
        component: ShopingCart,
        beforeEnter: (to, from, next) => {
            console.log(to, from);
            if (!localStorage.getItem("token")) {
                next({
                    path: '/Login'
                })
            } else {
                next()
            }
        }
    },
    {
        path: '/Password',
        name: 'Password',
        component: Password
    },


]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})

export default router